package codeine.servlets;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import codeine.configuration.directory.PeersListJson;
import codeine.servlet.AbstractServlet;

public class PeerPortServlet extends AbstractServlet{

	private static final Logger log = Logger.getLogger(PeerPortServlet.class);

	private static final long serialVersionUID = 1L;
	
	@Inject	private PeersListJson peersList;
	
	@Override
	protected void myGet(HttpServletRequest request, HttpServletResponse response) {
		String hostname = request.getParameter("peer");
		String install_dir = request.getParameter("install_dir");
		log.info("get with params peer " + hostname + " install dir " + install_dir);
		int port = peersList.findPort(hostname, install_dir);
		log.info("port for peer " + hostname + ":" + install_dir + " is " + port);
		getWriter(response).write(String.valueOf(port));
	}

}
